package 腾讯;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author zhangmin
 * @create 2022-04-24 21:30
 */
public class Main5 {
    static long maxres=0;
    //sum现金，count持有的股票数量
    public static void dp(int[] nums,int day,int sum,int count){
        if (sum<0||count<0) return;
        if (day==nums.length)return;
        if (day==nums.length-1){
            int res=count*nums[nums.length-1]+sum;
            maxres=Math.max(maxres,res);
            return;
        }

        //选择day天是买还是买还是持有
        dp(nums,day+1,sum-nums[day],count+1);
        dp(nums,day+1,sum+nums[day],count-1);
        dp(nums,day+1,sum,count);
    }
    public static void main(String[] args) {
        Scanner cin=new Scanner(System.in);
        int n=cin.nextInt();
        int m=cin.nextInt();
        int[] nums=new int[n];
        for (int i = 0; i < n; i++) {
            nums[i]=cin.nextInt();
        }
        dp(nums,0,m,0);
        System.out.println(maxres);
    }

}
